﻿<UserControl x:Class="MovieCollection.MovieControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:movieCollection="clr-namespace:MovieCollection"
    xmlns:avalonControls="clr-namespace:AC.AvalonControlsLibrary.Controls;assembly=AvalonControlsLibrary"
    x:Name="movieControl" Height="Auto" Width="600">
    <UserControl.Resources>
        <movieCollection:ImageToImageSourceConverter x:Key="imageConverter" />
        <movieCollection:MediaFileToMediaFileSizeText x:Key="mediaFileConverter" />
        <movieCollection:ListToStringConverter x:Key="listToString" />
        <Image x:Shared="False" x:Key="NoCoverImage" Source="Icons/noImage.png" />
    </UserControl.Resources>
    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="36" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <TextBox x:Name="textBoxTitle" Grid.Column="0" Grid.Row="0" Margin="5 5 2.5 2.5" FontSize="16" FontWeight="Bold" KeyUp="textBoxTitle_KeyUp"
                 Text="{Binding Movie.Title, ElementName=movieControl, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/>
            <Button x:Name="buttonWebSearch" Grid.Column="1" Grid.Row="0" Content="{LocText MovieCollection::ButtonWebSearch}" Margin="2.5 5 5 2.5"
                Click="buttonWebSearch_Click"/>
            <Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MaxWidth="140" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="160" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Button x:Name="buttonCover" Grid.Column="0" Grid.Row="0" Margin="5" ToolTip="{LocText MovieCollection::ImageCover}"
                    Click="buttonCover_Click" MouseRightButtonUp="buttonCover_MouseRightButtonUp" >
                    <Image x:Name="imageCover" Source="{Binding Movie.Cover, ElementName=movieControl, 
                    Converter={StaticResource imageConverter}, ConverterParameter={StaticResource NoCoverImage}}"
                   VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Button>
                <Grid Grid.Column="1" Grid.Row="0" Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="28" />
                        <RowDefinition Height="28" />
                        <RowDefinition Height="28" />
                        <RowDefinition Height="28" />
                        <RowDefinition Height="38" />
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0" Text="{LocText MovieCollection::LabelOriginalTitle}" FontWeight="Bold"
                           Margin="2.5" HorizontalAlignment="Right" VerticalAlignment="Center" />
                    <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Movie.OriginalTitle, ElementName=movieControl}" Margin="2.5" />
                    
                    <TextBlock Grid.Column="0" Grid.Row="1" Text="{LocText MovieCollection::LabelDirector}" FontWeight="Bold"
                           Margin="2.5" HorizontalAlignment="Right" VerticalAlignment="Center" />
                    <TextBox x:Name="textBoxDirectors" Grid.Column="1" Grid.Row="1" Text="{Binding Movie.Directors, ElementName=movieControl, Converter={StaticResource listToString}, Mode=OneWay}" 
                               Margin="2.5" VerticalAlignment="Center" LostFocus="textBoxDirectors_LostFocus" ToolTip="{LocText MovieCollection::TextBoxDirectorsToolTip}"  />
                    
                    <TextBlock Grid.Column="0" Grid.Row="2" Text="{LocText MovieCollection::LabelYear}" FontWeight="Bold"
                           Margin="2.5" HorizontalAlignment="Right" VerticalAlignment="Center" />
                    <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Movie.Year, ElementName=movieControl}" Margin="2.5" />
                    
                    <TextBlock Grid.Column="0" Grid.Row="3" Text="{LocText MovieCollection::LabelCountry}" FontWeight="Bold"
                           Margin="2.5" HorizontalAlignment="Right" VerticalAlignment="Center" />
                    <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding Movie.Country, ElementName=movieControl}" Margin="2.5" />
                    
                    <TextBlock Grid.Column="0" Grid.Row="4" Text="{LocText MovieCollection::LabelRating}" FontWeight="Bold"
                           Margin="2.5" HorizontalAlignment="Right" VerticalAlignment="Center" />
                    <Grid Grid.Column="1" Grid.Row="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <avalonControls:RatingSelector Grid.Column="0" Grid.Row="0" Margin="2.5" MinRating="0" MaxRating="10" RateItemColor="DarkOrange"
                               RatingSelected="{Binding Movie.Rating, ElementName=movieControl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Movie.Rating, ElementName=movieControl}" 
                               Width="25" VerticalAlignment="Center" TextAlignment="Center" />
                    </Grid>
                </Grid>
                <StackPanel Orientation="Vertical" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1">
                    <TextBlock Text="{LocText MovieCollection::TextBlockPlot}" Height="20" Width="Auto" FontWeight="Bold" 
                           VerticalAlignment="Center" Padding="5 1.5 0 0" />
                    <TextBox Text="{Binding Movie.Plot, ElementName=movieControl}" MinHeight="80" Height="Auto" Margin="2.5" 
                         TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />
                </StackPanel>
                <Expander x:Name="expanderGenre" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Expanded="expanderGenre_Expanded" Collapsed="expanderGenre_Collapsed">
                    <Expander.Header>
                        <TextBlock Text="{LocText MovieCollection::ExpanderGenre}" FontWeight="Bold" />
                    </Expander.Header>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="32" />
                        </Grid.RowDefinitions>
                        
                        <ListBox x:Name="listBoxGenre" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0"
                                 BorderBrush="Transparent" Margin="2.5" SelectionChanged="listBoxGenre_SelectionChanged" HorizontalContentAlignment="Center"
                                 ItemsSource="{Binding Movie.Genres, ElementName=movieControl}" SelectionMode="Extended" />
                        <Button x:Name="buttonAddGenre" Grid.Column="0" Grid.Row="1" Margin="5" MinWidth="100" HorizontalContentAlignment="Center" HorizontalAlignment="Right"
                                Click="buttonAddGenre_Click">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="24" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Image Source="Icons/edit_add.png" Width="16" Height="16" Grid.Column="0" Grid.Row="0" />
                                <TextBlock Text="{LocText MovieCollection::ButtonAdd}" Grid.Column="1" Grid.Row="0" Margin="5 0 0 0" />
                            </Grid>
                        </Button> 
                        <Button x:Name="buttonDeleteGenre" Grid.Column="1" Grid.Row="1" Margin="5" MinWidth="100" HorizontalAlignment="Left"
                                HorizontalContentAlignment="Center" Click="buttonDeleteGenre_Click" IsEnabled="False">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="24" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Image Source="Icons/edit_remove.png" Width="16" Height="16" Grid.Column="0" Grid.Row="0" />
                                <TextBlock Text="{LocText MovieCollection::ButtonDelete}" Grid.Column="1" Grid.Row="0" Margin="5 0 0 0" />
                            </Grid>
                        </Button>
                    </Grid>
                </Expander>
                <Expander x:Name="expanderCast" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Expanded="expanderCast_Expanded" Collapsed="expanderCast_Collapsed">
                    <Expander.Header>
                        <TextBlock Text="{LocText MovieCollection::ExpanderCast}" FontWeight="Bold" />
                    </Expander.Header>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <ListBox x:Name="listBoxCast" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0"
                                 BorderBrush="Transparent" Margin="2.5" SelectionChanged="listBoxCast_SelectionChanged" HorizontalContentAlignment="Center"
                                 ItemsSource="{Binding Movie.Cast, ElementName=movieControl}" SelectionMode="Extended" />
                        <Button x:Name="buttonAddCast" Grid.Column="0" Grid.Row="1" Margin="5" MinWidth="100" HorizontalAlignment="Right"
                                HorizontalContentAlignment="Center" Click="buttonAddCast_Click">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="24" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Image Source="Icons/edit_add.png" Width="16" Height="16" Grid.Column="0" Grid.Row="0" />
                                <TextBlock Text="{LocText MovieCollection::ButtonAdd}" Grid.Column="1" Grid.Row="0" Margin="5 0 0 0" />
                            </Grid>
                        </Button>
                        <Button x:Name="buttonDeleteCast" Grid.Column="1" Grid.Row="1" Margin="5" MinWidth="100" HorizontalAlignment="Left"
                                HorizontalContentAlignment="Center" Click="buttonDeleteCast_Click" IsEnabled="False">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="24" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Image Source="Icons/edit_remove.png" Width="16" Height="16" Grid.Column="0" Grid.Row="0" />
                                <TextBlock Text="{LocText MovieCollection::ButtonDelete}" Grid.Column="1" Grid.Row="0" Margin="5 0 0 0" />
                            </Grid>
                        </Button>
                    </Grid>
                </Expander>
                <GroupBox x:Name="groupBoxMediaFile" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4" Height="Auto" Margin="2.5" BorderBrush="DarkGray">
                    <GroupBox.Header>
                        <TextBlock Text="{Binding Movie.MediaFile.Size, ElementName=movieControl, Converter={StaticResource mediaFileConverter}}" FontWeight="Bold" />
                    </GroupBox.Header>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBox x:Name="textBoxMediaFile" Grid.Column="0" Grid.Row="0" Margin="2.5" TextChanged="textBoxMediaFile_TextChanged" 
                             Text="{Binding Movie.MediaFile.Path, ElementName=movieControl, Mode=OneWay}" />
                        <Button x:Name="buttonBrowseMediaFile" Grid.Column="1" Grid.Row="0" Margin="2.5" Padding="5 0 5 0" Click="buttonBrowseMediaFile_Click"
                            Content="{LocText MovieCollection::ButtonBrowse}" ToolTip="{LocText MovieCollection::ButtonBrowseToolTip}"  />
                        <Button x:Name="buttonPlay" Grid.Column="2" Grid.Row="0" Margin="2.5" Padding="5 0 5 0" Click="buttonPlay_Click"
                            Content="{LocText MovieCollection::ButtonPlay}" />
                        <StackPanel x:Name="stackPanelVideo" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Orientation="Horizontal" Height="Auto" >
                            <TextBlock Text="{LocText MovieCollection::LabelVideo}" VerticalAlignment="Center" Margin="2.5" FontWeight="Bold"/>
                            <Label x:Name="labelVideo" Content="{Binding Movie.MediaFile.Video, ElementName=movieControl}" Margin="2.5" />
                        </StackPanel>
                        <StackPanel x:Name="stackPanelAudio" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2" Orientation="Horizontal" Height="Auto" >
                            <TextBlock Text="{LocText MovieCollection::LabelAudio}" VerticalAlignment="Center" Margin="2.5" FontWeight="Bold"/>
                            <ListBox x:Name="listBoxAudio" Background="Transparent" BorderBrush="Transparent" Margin="2.5" SelectionChanged="listBoxAudio_SelectionChanged"
                             ItemsSource="{Binding Movie.MediaFile.Audio, ElementName=movieControl}" />
                        </StackPanel>
                        <StackPanel x:Name="stackPanelLogos" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="3" Orientation="Horizontal" />
                    </Grid>
                </GroupBox>
                <GroupBox x:Name="groupBoxUserSettings" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="5" Height="Auto" Margin="2.5" BorderBrush="DarkGray">
                    <GroupBox.Header>
                        <TextBlock Text="{LocText MovieCollection::GroupBoxUserSettings}" FontWeight="Bold" />
                    </GroupBox.Header>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <CheckBox x:Name="checkBoxSeen" Grid.Column="0" Grid.Row="0" Content="{LocText MovieCollection::CheckBoxSeen}"
                          VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 5 10 5"
                          IsChecked="{Binding UserSettings.Seen, ElementName=movieControl}" FontWeight="Bold" />
                        <TextBlock Grid.Column="1" Grid.Row="0" Text="{LocText MovieCollection::LabelRating}" FontWeight="Bold"
                               VerticalAlignment="Center" Margin="5" />
                        <Grid Grid.Column="2" Grid.Row="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <avalonControls:RatingSelector Grid.Column="0" Grid.Row="0" Margin="2.5" MinRating="0" MaxRating="10" RateItemColor="DarkOrange"
                               RatingSelected="{Binding UserSettings.Rating, ElementName=movieControl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding UserSettings.Rating, ElementName=movieControl}" 
                               Width="25" VerticalAlignment="Center" TextAlignment="Center" />
                        </Grid>
                        <TextBlock Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Text="{LocText MovieCollection::LabelComment}" Margin="2.5" FontWeight="Bold" />
                        <TextBox Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2" Margin="2.5"  
                             Text="{Binding UserSettings.Comment, ElementName=movieControl}"/>
                    </Grid>
                </GroupBox>
            </Grid>
        </Grid>
    </ScrollViewer>
</UserControl>
